<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="schoolId">
        <el-select @change="getAdviser" v-model="queryParams.schoolId" placeholder="请输入所属校区" clearable
                   :style="{width: '100%'}">
          <el-option v-for="(item, index) in schoolIdOptions" :key="index" :label="item.schoolName"
                     :value="item.schoolId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="userId">
        <el-select v-model="queryParams.userId" placeholder="请输入课程顾问" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in postIdOptions" :key="index" :label="item.nickName"
                     :value="item.userId" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学员姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="studentPhone">
        <el-input
          v-model="queryParams.studentPhone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['student:intentionStu:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['student:intentionStu:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-row :gutter="10" class="mb8">
      <el-col :span="12">
        <div style="margin-bottom: 1.5%">
          <li class="el-icon-user-solid"></li>
          <span style="font-size: 14px"> 意向学员:  </span>
          <span style="padding:1px;background-color: #00afff;font-size: 12px;font-weight: bold;color: white">
            {{'总计'+total+'人'}}
          </span>
        </div>
      </el-col>
    </el-row>
    <el-table stripe border v-loading="loading" :data="intentionStuList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="学生编号" align="left" prop="studentNumber">
        <template slot-scope="scope">
          <span style="color: #00afff">
            <i class="el-icon-user-solid"></i>
            <span v-text="scope.row.studentNumber"></span>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="学员姓名" align="left" prop="studentName">
        <template slot-scope="scope">
         <div>{{scope.row.studentName}}</div>
          <div style="font-size: 2px" v-text="scope.row.studentPhone"></div>
        </template>
      </el-table-column>
      <el-table-column label="所属校区" align="left" prop="schoolName">
        <template slot-scope="scope">
          <span v-text="scope.row.schoolName" style="background-color: #00afff;font-weight:bold;color:white;padding:3px">
          </span>
        </template>
      </el-table-column>
      <el-table-column label="出生日期" align="left" prop="studentBirthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.studentBirthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="学生性别" align="left" prop="studentSex">
        <template slot-scope="scope">
          <span>
            <i v-if="scope.row.studentSex == '男'" class="el-icon-male" style="color:cornflowerblue;margin-right: 5px"></i>
            <i v-if="scope.row.studentSex == '女'" class="el-icon-female" style="color: red;margin-right: 5px"></i>
            <span v-text="scope.row.studentSex"></span>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="所属销售" align="left" prop="nickName">
        <template slot-scope="scope">
          <div>
            <div v-text="scope.row.nickName"></div>
            <div style="font-size: 5px" v-text="scope.row.phonenumber"></div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="追踪情况" align="left" prop=""/>
      <el-table-column label="学员标签" align="left" prop=""/>
      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['student:intentionStu:edit']">修改</el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['student:intentionStu:remove']">删除</el-button>
              </template>
            </el-table-column>-->
    </el-table>

    <div class="block">
      <el-pagination :page-size="queryParams.pageSize" layout="total,prev, pager, next" @current-change="currentChange"
                     :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {getIntentionStu, getAdviser, getListSchool} from "../../../api/student/student";

export default {
  name: "IntentionStu",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生表格数据
      intentionStuList: [],
      //获取所有校区
      schoolIdOptions: [],
      /*获取所有课程顾问*/
      postIdOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentName: null,
        studentPhone: null,
        schoolId: null,
        userId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
    this.school();
    this.getAdviser()
  },
  methods: {
    /** 查询学生列表 */
    getList() {
      this.loading = true;

      getIntentionStu(this.queryParams).then((res) => {
        this.intentionStuList = res.data
        this.total =res.count
        this.loading = false;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.studentId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({path: "/student/register"})
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有学生数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportIntentionStu(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    },
    /*获取所有校区*/
    school() {
      getListSchool().then((res) => {
        this.schoolIdOptions = res.data
      })
    },
    getAdviser() {
      getAdviser().then((res) => {
        this.postIdOptions = res.data
      })
    },
    /*分页*/
    currentChange(current) {
      this.queryParams.pageNum = current;
      this.getList()
    }
  }
};
</script>
